package com.zzh.compilation.syntax;

import com.zzh.compilation.model.Token;
import com.zzh.compilation.lexical.LexicalAnalyzer;

import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // begin a:=9;x:=2*3 ; b:=a+x end #    success
        // x:=a+b*c end #                      error

        // 设置输入字符串
        System.out.println("Enter your code (end with # on a new line):");
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if ("#".equals(line)) {
                break;
            }
//            if ("end#".equals(line)){
//                break;
//            }
            LexicalAnalyzer.inputBuilder.append(line).append('\n');
        }
        List<Token> tokens = LexicalAnalyzer.analyze();
        for (Token token : tokens) {
            System.out.println("line:" + token.getLineNumber() + "  (" + token.getType() + ", " + token.getValue() + ")");
        }
        // 语法分析
        SyntaxAnalyzer.analyze(tokens);
    }
}